package com.upcode.weighing.util.ops;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import java.util.List;

public class PageUtil {

    public static PageInfo pageList(List list,Integer pageNum,Integer pageSize){
        if(pageNum==null){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        Page page = new Page(pageNum, pageSize);
        int total = list.size();
        page.setTotal(total);
        int startIndex = (pageNum - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize,total);
        page.addAll(list.subList(startIndex,endIndex));
        PageInfo pageInfo = new PageInfo(page);
        return pageInfo;
    }
}
